import { BillboardController, getIcon } from '../utils'
import { useDataFetching } from './useDataFetching'
import { riskPointCoverage } from '../api'
import type { IconMap } from '../types'

export function usePlacementRiskMark(billboardController: BillboardController, iconMap: IconMap) {
  billboardController.setFieldMappings({
    type: 'riskTypeName',
  })
  // 处理撒点逻辑
  const { executeRequest } = useDataFetching<any[]>(riskPointCoverage, (data) => {
    console.log('🚀 ~ usePlacementRiskMark ~ data:', data)
    // 撒点逻辑
    data = data.map((e) => {
      return { ...e, image: getIcon(e.riskTypeName, iconMap) }
    })
    billboardController.batchAdd(data)
  })

  return {
    executeRequest,
  }
}
